package com.shop2cn.app.liveseller.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.app.liveseller.parameter.CreateSellerLiveBean;
import com.shop2cn.app.liveseller.parameter.RemoveLiveBean;
import com.shop2cn.app.liveseller.service.RemoveLiveCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.LiveRoom;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
/**
*移除继承直播间
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RemoveLive{
	private static RemoveLiveBean removeliveBean;
	private static RemoveLiveCall removeliveCall;
	private static LiveRoomShop2cnWapper LiveRoomShop2cnWapper;
	private static int sellerId ;
	private static String token ;
	private static int csId;
	private static String cstoken;
	private static int mchId_Agent;
	@BeforeClass
	public static void setUp() throws Exception {
		Logger.createResultFile("移除继承直播间");
		sellerId = GodmchManageCallService.CreateSellerMch();
		token=AuthCallServiceV2.createToken(sellerId, "app");
		csId = GodmchManageCallService.bindClientService(
				sellerId, 1);
		cstoken = AuthCallServiceV2.createToken(csId, "app");
		 mchId_Agent=GodmchManageCallService.createAgent(sellerId);
	}

	@Before
	public void caseUp() {
		removeliveBean=new RemoveLiveBean();
		removeliveCall=new RemoveLiveCall();
		LiveRoomShop2cnWapper=new LiveRoomShop2cnWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(removeliveCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveLive_001() {
		Logger.start(true,"移除继承直播间成功");
		try {
			 CreateSellerLiveBean c = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			 c.getLiveDto().setLiveInherit(true);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(c,sellerId);
			LiveRoomShop2cnCallService.AddLiveToShop(createlive.getId(),mchId_Agent , sellerId);
			
			removeliveBean.setInheritUserId(mchId_Agent);
			removeliveBean.setLiveRoomId(createlive.getId());
			removeliveCall.setData(removeliveBean);
			String head="accesstoken="+token;
			removeliveCall.addHeader("ymt-pars", head);
			removeliveCall.callService();			
			Logger.verifyEquals("{}", removeliveCall.getReturnData(), "验证Code");
			List<Map> map1 = LiveRoomShop2cnWapper.selectLiveInheritrelation(createlive.getId(), mchId_Agent);
			Logger.debug(map1);
			Logger.verifyEquals(map1.get(0).get("Status").toString(), "0", "验证关系");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RemoveLive_002() {
		Logger.start(true,"不输入liveRoomId失败");
		try {
			removeliveBean.setInheritUserId(mchId_Agent);
//			removeliveBean.setLiveRoomId(createlive.getId());
			removeliveCall.setData(removeliveBean);
			String head="accesstoken="+token;
			removeliveCall.addHeader("ymt-pars", head);
			removeliveCall.callService();			
			Logger.verifyEquals("400", removeliveCall.getString("code"), "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RemoveLive_003() {
		Logger.start(true,"不输入inheritUserId失败");
		try {
//			removeliveBean.setInheritUserId(mchId_Agent);
			removeliveBean.setLiveRoomId(1);
			removeliveCall.setData(removeliveBean);
			String head="accesstoken="+token;
			removeliveCall.addHeader("ymt-pars", head);
			removeliveCall.callService();			
			Logger.verifyEquals("400", removeliveCall.getString("code"), "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}